<html>
<head><meta charset="utf-8"><title>name resolution · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/name.20resolution.html">name resolution</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="158530205"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/name%20resolution/near/158530205" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/name.20resolution.html#158530205">(Feb 14 2019 at 13:52)</a>:</h4>
<p>what's the difference between <code>HirDatabase</code> and <code>PersistentHirDatabase</code>?</p>
<p>I'm asking because I wanted to into resolution for associated items, and I'm not sure how to implement it. I can handle <code>ModuleDef::Struct</code> <a href="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_hir/src/nameres.rs#L635" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_hir/src/nameres.rs#L635">here</a>, but I'm not sure how to reach the item.</p>



<a name="158530324"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/name%20resolution/near/158530324" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/name.20resolution.html#158530324">(Feb 14 2019 at 13:54)</a>:</h4>
<p>my <a href="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_hir/src/ty/method_resolution.rs#L180" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_hir/src/ty/method_resolution.rs#L180"><code>iterate_impl_items</code></a> takes a <code>HirDatabase</code></p>



<a name="158530745"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/name%20resolution/near/158530745" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/name.20resolution.html#158530745">(Feb 14 2019 at 14:00)</a>:</h4>
<p>not sure if that makes sense (:</p>



<a name="158532153"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/name%20resolution/near/158532153" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/name.20resolution.html#158532153">(Feb 14 2019 at 14:22)</a>:</h4>
<p><code>PersistentHirDatabase</code> (to be renamed to <code>DefsDatabase</code> maybe?) is for parts of the IDE where we want incrementallity. </p>
<p><code>HirDatabase</code> is for stuff where we want to be lazy, but don't need to be incremental. </p>
<p>Roughly speaking, everything about types should go to <code>HirDatabase</code>, because it should be ok to re-typecheck a function for completion, everything about macro resolution and modules should go to PersistentHirDatabase</p>



<a name="158532209"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/name%20resolution/near/158532209" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/name.20resolution.html#158532209">(Feb 14 2019 at 14:23)</a>:</h4>
<p><code>resolve_path_fp</code> is for the module-level resolution: it should resolve the path up to the first associated item.</p>



<a name="158532274"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/name%20resolution/near/158532274" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/name.20resolution.html#158532274">(Feb 14 2019 at 14:24)</a>:</h4>
<p>Everything else should be handled separately, by the type checker.</p>



<a name="158532284"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/name%20resolution/near/158532284" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/name.20resolution.html#158532284">(Feb 14 2019 at 14:24)</a>:</h4>
<p>I can make <code>String::new()</code> resolve to <code>String</code>, but that's not too useful. I'm not sure what happens to the last segment</p>



<a name="158532331"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/name%20resolution/near/158532331" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/name.20resolution.html#158532331">(Feb 14 2019 at 14:25)</a>:</h4>
<p>I <em>think</em> associated item resolution should be handled somewhere aroud <a href="https://github.com/rust-analyzer/rust-analyzer/blob/b85c189500a47f3c5f7690250611b06e08616c9a/crates/ra_hir/src/ty.rs#L1107-L1132" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/blob/b85c189500a47f3c5f7690250611b06e08616c9a/crates/ra_hir/src/ty.rs#L1107-L1132">https://github.com/rust-analyzer/rust-analyzer/blob/b85c189500a47f3c5f7690250611b06e08616c9a/crates/ra_hir/src/ty.rs#L1107-L1132</a></p>



<a name="158532432"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/name%20resolution/near/158532432" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/name.20resolution.html#158532432">(Feb 14 2019 at 14:27)</a>:</h4>
<p>Ie, for <code>String::new</code> the resolver should say "I've resolved <code>String</code> Def, but I don't know what <code>new</code> is" , and the typechecker should look at the type of the <code>String</code> and find the associated method.</p>



<a name="158532435"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/name%20resolution/near/158532435" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/name.20resolution.html#158532435">(Feb 14 2019 at 14:27)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="129457">@Florian Diebold</span></p>



<a name="158554175"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/name%20resolution/near/158554175" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/name.20resolution.html#158554175">(Feb 14 2019 at 18:55)</a>:</h4>
<p>Yes... The first step would be to make the resolver actually return partial resolutions (i.e. what did the part that could be resolved resolve to, and what segments still remain), and then we can start handling that in <code>ty.rs</code></p>



<a name="158554444"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/name%20resolution/near/158554444" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/name.20resolution.html#158554444">(Feb 14 2019 at 18:58)</a>:</h4>
<p>so I think for now there would be additional handling after <a href="https://github.com/rust-analyzer/rust-analyzer/blob/b85c189500a47f3c5f7690250611b06e08616c9a/crates/ra_hir/src/ty.rs#L1107" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/blob/b85c189500a47f3c5f7690250611b06e08616c9a/crates/ra_hir/src/ty.rs#L1107">https://github.com/rust-analyzer/rust-analyzer/blob/b85c189500a47f3c5f7690250611b06e08616c9a/crates/ra_hir/src/ty.rs#L1107</a> for that case</p>



<a name="158555484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/name%20resolution/near/158555484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/name.20resolution.html#158555484">(Feb 14 2019 at 19:12)</a>:</h4>
<blockquote>
<p>The first step would be to make the resolver actually return partial resolutions (i.e. what did the part that could be resolved resolve to, and what segments still remain)</p>
</blockquote>
<p>Should <code>PerNs</code> be an enum? I'm not sure what <code>types</code> and <code>values</code> are.</p>



<a name="158555731"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/name%20resolution/near/158555731" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/name.20resolution.html#158555731">(Feb 14 2019 at 19:16)</a>:</h4>
<p>They're the different namespaces. A name may resolve to different definitions depending on whether you're looking for a type or a value.<br>
I think one possible representation would be <code>(PerNs&lt;Resolution&gt;, &amp;[PathSegment])</code>, although then callers need to make sure to check whether the path fully resolved; or an enum with <code>PartiallyResolved(PerNs&lt;Resolution&gt;, &amp;[PathSegment]), FullyResolved(PerNs&lt;Resolution&gt;)</code>... not sure</p>



<a name="158555844"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/name%20resolution/near/158555844" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/name.20resolution.html#158555844">(Feb 14 2019 at 19:17)</a>:</h4>
<p>I suppose that makes sense. And methods should be... values, I guess? But it wouldn't matter in my case, because the resolution would stop at the parent struct.</p>



<a name="158555867"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/name%20resolution/near/158555867" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/name.20resolution.html#158555867">(Feb 14 2019 at 19:18)</a>:</h4>
<p>Maybe I should watch that rust-analyzer video</p>



<a name="158621951"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/name%20resolution/near/158621951" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eulerdisk <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/name.20resolution.html#158621951">(Feb 15 2019 at 15:25)</a>:</h4>
<p>Hi guys, I just skimmed over name resolution. From what I see resolving use imports inside functions/blocks is not implemented, right? Are there any plans for that?<br>
[Maybe I can try to do it myself, if there are no blockers]</p>



<a name="158623418"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/name%20resolution/near/158623418" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/name.20resolution.html#158623418">(Feb 15 2019 at 15:44)</a>:</h4>
<p>Yes it's not implemented yet. There are plans in the sense of "we need to implement this sometime", but no one has started working on it as far as I know ;)<br>
I don't think there are concrete blockers, but it's kind of complicated -- basically any block that contains items is its own anonymous module, which we need to include in the fixpoint import resolution. Anonymous modules inherit the scope from their parent module (as opposed to named modules, which don't).</p>



<a name="158687147"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/name%20resolution/near/158687147" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/name.20resolution.html#158687147">(Feb 16 2019 at 09:47)</a>:</h4>
<blockquote>
<p>, which we need to include in the fixpoint import resolution. </p>
</blockquote>
<p>Probably not literary include: I think macros declared inside of functions, even in modules, cant escape to the outer scope, so in theory we should be able to resolve each item's block independently. That is, we could run a separate fixed-point iteration per function.</p>



<a name="163449410"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/name%20resolution/near/163449410" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/name.20resolution.html#163449410">(Apr 16 2019 at 08:10)</a>:</h4>
<p>We hadn't had a meeting for a while, and we really should move forward with nameresolution librarification. So, let's discuss it (probably on Zulip?):</p>
<p><a href="https://doodle.com/poll/i9mi98urqry6mxnr" target="_blank" title="https://doodle.com/poll/i9mi98urqry6mxnr">https://doodle.com/poll/i9mi98urqry6mxnr</a></p>
<p>cc <span class="user-group-mention" data-user-group-id="1060">@WG-rls2.0</span> </p>
<p>The key person here is <span class="user-mention" data-user-id="116083">@pnkfelix</span> , but, if <span class="user-mention" data-user-id="116009">@nikomatsakis</span> were available, that'd be cool!</p>



<a name="163532487"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/name%20resolution/near/163532487" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/name.20resolution.html#163532487">(Apr 17 2019 at 05:22)</a>:</h4>
<p>Heh, not a lot of participants on the poll :)</p>
<p><span class="user-mention" data-user-id="116083">@pnkfelix</span> let's schedule this for tomorrow than, the same time as today's meeting about RLS 1/2</p>



<a name="163548007"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/name%20resolution/near/163548007" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/name.20resolution.html#163548007">(Apr 17 2019 at 10:18)</a>:</h4>
<p>sure, that sounds fine with me. Hopefully niko can make it</p>



<a name="165055522"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/name%20resolution/near/165055522" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/name.20resolution.html#165055522">(May 07 2019 at 09:22)</a>:</h4>
<p>Hey, <span class="user-mention" data-user-id="116083">@pnkfelix</span> let's discuss name resolution stuff this week? I guess we can do this in async-way in this thread</p>



<a name="165061375"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/name%20resolution/near/165061375" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/name.20resolution.html#165061375">(May 07 2019 at 11:09)</a>:</h4>
<p>sure; I don't have much to report yet. I'm trying to tie off an incremental compilation bug before I switch over to this</p>



<a name="165063226"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/name%20resolution/near/165063226" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/name.20resolution.html#165063226">(May 07 2019 at 11:40)</a>:</h4>
<p>Cool: fixing that incremental bug will surely have a positive impact on rust-analyzer development velocity :D</p>
<p>We still need to get to name resolution at some point: our macro and trait story is maturing fast, so nameres could become a blocker soon-ish</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>